﻿@using System.Text
@using OA.Model
@using OA.AspNetCore.Html
@using OA.Core.Model
@using OA.Core.Helper

@model List<SimplePermissionGroup>
@{
    string empID = ViewBag.EmpID;
    Layout = "~/Areas/Member/Views/Shared/_layer_layout.cshtml";
}

<form class="layui-form" action="">
    <div class="layui-form-item" pane="">
        <label class="layui-form-label">权限组</label>
        <div class="layui-input-block">
            @foreach (var item in Model)
            {
                if (item.IsSelected)
                {
                    <input type="checkbox" value="@item.ID" name="Permission" lay-filter="Permission" lay-skin="primary" title="@item.Name" checked="">
                }
                else
                {
                    <input type="checkbox" name="Permission" value="@item.ID" lay-filter="Permission" lay-skin="primary" title="@item.Name">
                }
            }

        </div>
    </div>
</form>
<script>
        layui.use(['element', 'layer','form'], function () {
            var element = layui.element;
            var layer = layui.layer;
            var form = layui.form;
            form.on('checkbox(Permission)', function (data) {
                var status = 0;
                if (this.checked) {
                    status = 1;
                }
                var url = "/Management/Employee/AddPermissionGroup?empID=@empID&PermissionGroupID=" + data.value+"&status="+status;
                $.getJSON(url, function (data) {
                    if (data.State == 200) {
                        if (status == 1) {
                            layer.msg("权限组添加成功!")
                        }
                        else {
                            layer.msg("权限组取消成功!")
                        }
                    }
                    else {
                        layer.msg(data.Message);
                        if (status == 1) {
                            myObj.prop('checked', false);
                        }
                        else {
                            myObj.prop('checked', true);
                        }
                    }
                });
            });

        });
</script>
